package org.study.event.core.eventbus.impl;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.study.event.core.eventbus.AbstractGuavaEventBusManager;

import com.google.common.eventbus.AsyncEventBus;

/***
 * 异步EventBus
 * 
 * @author 陈波
 *
 */
public class AsyncGuavaEventBusManager extends AbstractGuavaEventBusManager {

	private ExecutorService executorService;
	
	public AsyncGuavaEventBusManager() {
		this.executorService = Executors.newCachedThreadPool();
	}

	public AsyncGuavaEventBusManager(int poolSize) {
		this.executorService = Executors.newFixedThreadPool(poolSize);
	}

	public void setExecutorService(ExecutorService executorService) {
		this.executorService = executorService;
	}

	@Override
	public void initEventBus() {
		if (this.identifier != null) {
			this.eventBus = new AsyncEventBus(identifier, executorService);
			return;
		}
		if (this.subscriberExceptionHandler != null) {
			this.eventBus = new AsyncEventBus(executorService, subscriberExceptionHandler);
			return;
		}
		this.eventBus = new AsyncEventBus(executorService);
	}

}
